<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class AdminController extends Controller {

	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	public $layout = '/layouts/2col-left';
	
	/**
	 * @return array action filters
	 */
	public function filters() {
		return array(
			'accessControl', // perform access control for CRUD operations
			'postOnly + delete' // we only allow deletion via POST request
		);
	}
	
	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules() {
		return array(
			array('allow',
				'actions' => array('login'),
				'users' => array('?')
			),
			array('allow',
				'actions' => array('*'),
				'users' => array('admin')
			),
			array(
				'deny', // deny all users
				'users' => array('?')
			)
		);
	}
	
	protected function beforeAction($action) {
		// set theme
		Yii::app()->setTheme('backend');

		// set page title
		$ctl = ucfirst($action->getController()->getId());
		$act = ucfirst($action->getId());
		if ($act=='Index') $act = "Manage";
		$this->pageTitle = Yii::app()->name." - $act $ctl";
		
		// set language
		Yii::app()->language = TranslateForm::model()->getCurrentLanguage();
		return true;
	}

}